﻿namespace ExamV5.ZiExam
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class ExamInput : Page
    {
        protected Button butDefault;
        protected DropDownList DDLWorker;
        protected HtmlForm Form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private PublicFun publicFun_0 = new PublicFun();
        protected RadioButtonList RBLType;
        protected ScriptManager SM;
        protected TextBox txtAgeInfo;
        protected TextBox txtUserCode;
        protected TextBox txtUserName;
        protected UpdatePanel UPPart;

        protected void butDefault_Click(object sender, EventArgs e)
        {
            if (this.DDLWorker.SelectedItem.Value != "0")
            {
                if ((this.txtAgeInfo.Text.Trim() == ""))
                {
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckB", "alert('请输入正确的年龄信息！')", true);
                }
                else if (this.RBLType.SelectedIndex == -1)
                {
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckC", "alert('请选择考核类别！')", true);
                }
                else
                {
                    string values = this.publicFun_0.GetValues("select ExamTime from ZiSetInfo", "ExamTime");
                    if (values == "")
                    {
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckC", "alert('请联系管理员设置考核时间信息！')", true);
                    }
                    else if (this.publicFun_0.GetValues("select ID from ZiRubricInfo where Flag='" + this.RBLType.SelectedItem.Value + "'", "ID") != "")
                    {
                        if (this.RBLType.SelectedItem.Value == "A")
                        {
                            string str5 = DateTime.Now.ToShortDateString();
                            string str6 = DateTime.Now.ToShortDateString();
                            string str3 = "1";
                            string str7 = "0";
                            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                            connection.Open();
                            SqlCommand command = new SqlCommand("select * from ZiSetInfo where JoinUserCode like '%," + this.httpCookie_0.Value + ",%'", connection);
                            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                            if (reader.Read())
                            {
                                str5 = reader["ExamStart"].ToString();
                                str6 = reader["ExamEnd"].ToString();
                                str3 = reader["JoinNum"].ToString();
                                str7 = "1";
                            }
                            reader.Close();
                            command.Dispose();
                            connection.Close();
                            connection.Dispose();
                            if (str7 != "1")
                            {
                                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckD", "alert('您暂未纳入考试名单中，所以无法进入考场！')", true);
                                return;
                            }
                            string str4 = this.publicFun_0.GetValues("select Count(*) as CountInfo from ZiGradeInfo where ExamType='A' and UserCode='" + this.httpCookie_0.Value + "' and (Convert(datetime,ExamDate)>=Convert(dateTime,'" + str5 + "') and Convert(datetime,ExamDate)<=Convert(dateTime,'" + str6 + "'))", "CountInfo");
                            if (str4.Trim() == "")
                            {
                                str4 = "0";
                            }
                            if (Convert.ToInt16(str3) <= Convert.ToInt16(str4))
                            {
                                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckE", "alert('考核次数已超出，无法进入考场！')", true);
                                return;
                            }
                            if (this.publicFun_0.GetValues("select ExamTime from ZiSetInfo where getdate()>=Convert(datetime,ExamStart) and Convert(datetime,ExamEnd)>=getdate()", "ExamTime") == "")
                            {
                                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckF", "alert('考核有效时间过期或未到，无法进入考场！')", true);
                                return;
                            }
                        }
                        this.publicFun_0.ExecuteSql("delete ZiGradeInfo where ExamType='B' and ExamDate<dateadd(day,-1,getdate())");
                        string strSql = "insert into ZiGradeInfo(UserCode,UserName,Worker,AgeInfo,FenValue,IsPass,ExamDate,ExamType,RightNum) values";
                        strSql = strSql + "('" + this.httpCookie_0.Value + "','" + this.httpCookie_1.Value + "','" + this.DDLWorker.SelectedItem.Text + "'," + this.txtAgeInfo.Text.Trim() + ",0,'K',getdate(),'" + this.RBLType.SelectedItem.Value + "',0)";
                        int num = this.publicFun_0.RetrunExecute(strSql);
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BShowZiKS", string.Concat(new object[] { "ShowJoinExam('", num, "','", this.RBLType.SelectedItem.Value, "','", values, "')" }), true);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckC", "alert('请联系管理员设置打字题库信息！')", true);
                    }
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckA", "alert('请选择岗位信息！')", true);
            }
        }

        private void method_0()
        {
            try
            {
                SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                SqlCommand command = new SqlCommand("select UserGWName,UserAge from UserInfo where UserCode='" + this.httpCookie_0.Value + "'", connection);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                if (reader.Read())
                {
                    this.DDLWorker.SelectedIndex = -1;
                    this.DDLWorker.Items.FindByText(reader["UserGWName"].ToString()).Selected = true;
                    if (!(reader["UserAge"].ToString().Trim() != ""))
                    {
                        this.txtAgeInfo.Text = "0";
                    }
                    else
                    {
                        TimeSpan span = (TimeSpan)(DateTime.Now - Convert.ToDateTime(reader["UserAge"].ToString()));
                        this.txtAgeInfo.Text = Convert.ToInt32((double)(span.TotalDays / 365.0)).ToString();
                    }
                }
                reader.Close();
                reader.Close();
                command.Dispose();
                connection.Close();
                connection.Dispose();
            }
            catch
            {
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (Convert.ToInt32(ConfigurationManager.ConnectionStrings["OnlineNum"].ConnectionString) == 0x3a)
                {
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BTHB", "alert('该版本为特惠版，此功能未开放！')", true);
                }
                else if (!base.IsPostBack)
                {
                    this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString + "打字考核";
                    if (!(this.publicFun_0.ReturnPaperData() != "Yes"))
                    {
                        this.DDLWorker.DataTextField = "ParmName";
                        this.DDLWorker.DataValueField = "ParmValue";
                        this.DDLWorker.DataSource = this.publicFun_0.RetrunDataView("select ParmName,ParmValue from SysParmInfo where ParmMemo='GWName'");
                        this.DDLWorker.DataBind();
                        ListItem item = new ListItem("--请选择岗位--", "0");
                        this.DDLWorker.Items.Add(item);
                        this.DDLWorker.Items.FindByValue("0").Selected = true;
                        this.txtUserCode.Text = this.httpCookie_0.Value;
                        this.txtUserName.Text = this.httpCookie_1.Value;
                        this.method_0();
                        this.butDefault.Attributes.Add("onclick", "javascript:{if(confirm('确定要进入打字考核现场？')==false) return false;}");
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('此版本暂未授权,请与管理员联系！')", true);
                    }
                }
                else
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

